package com.example.servletdemo.listner.attribute;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

//@WebListener
public class MyServletContextAttributeListener implements ServletContextAttributeListener {
    private static final String TAG = "MyServletContextAttributeListener";

    //当程序把一个属性存入ServletContext时触发该方法
    @Override
    public void attributeAdded(ServletContextAttributeEvent event) {
        System.out.println(TAG+"=>attributeAdded"+" =>name:"+event.getName()+" value:"+event.getValue());
    }

    //当程序把一个属性替换ServletContext内的属性时触发该方法
    @Override
    public void attributeRemoved(ServletContextAttributeEvent event) {
        System.out.println(TAG+"=>attributeRemoved");
    }

    //当程序把一个属性从ServletContext删除时触发该方法
    @Override
    public void attributeReplaced(ServletContextAttributeEvent event) {
        System.out.println(TAG+"=>attributeReplaced");
    }
}
